<%@ page language="java" pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<script type="text/javascript">
	 var ctx = '${path}';
</script>
<!-- 全局js -->
<script src="${pageContext.request.contextPath}/assets/hplus/js/jquery.min.js?v=2.1.4"></script>
<script src="${pageContext.request.contextPath}/assets/hplus/js/bootstrap.min.js?v=3.3.7"></script>
<script src="${pageContext.request.contextPath}/assets/hplus/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="${pageContext.request.contextPath}/assets/hplus/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/hplus/js/plugins/layer/layer.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/hplus/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/hplus/js/plugins/layer/layer.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/hplus/js/plugins/iCheck/icheck.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/hplus/js/plugins/validate/jquery.validate.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/hplus/js/plugins/validate/messages_zh.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/hplus/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/content.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/plugins/jQuery-Autocomplete-master/dist/jquery.autocomplete.js"></script>
<!-- 自定义js -->
<script src="${pageContext.request.contextPath}/assets/js/search-suggest.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/app.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/jquery.editable-select.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/jquery.mockjax.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/jquery.autocomplete.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/countries.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/app.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/plugins/jquery.form.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/assets/hplus/js/plugins/layer/laydate/laydate.js"></script>
   <!-- jqGrid -->
<script src="${pageContext.request.contextPath}/assets/hplus/js/plugins/jqgrid/i18n/grid.locale-cn.js?0820"></script>
<script src="${pageContext.request.contextPath}/assets/hplus/js/plugins/jqgrid/jquery.jqGrid.min.js?0820"></script>

<script src="${pageContext.request.contextPath}/assets/js/common.js"></script>
<!--手机号 生分证，表单校验插件 -->
<script src="${pageContext.request.contextPath}/assets/js/validate/dist/additional-methods.js"></script>


<script type="text/javascript">

	function toTaskList() {
		document.location.href = '${path}/activiti/my_task_list';
	}

   $.validator.setDefaults({
          highlight: function (element) {
              $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
          },
          success: function (element) {
              element.closest('.form-group').removeClass('has-error').addClass('has-success');
          },
          errorElement: "span",
          errorPlacement: function (error, element) {
              if (element.is(":radio") || element.is(":checkbox")) {
                  error.appendTo(element.parent().parent().parent());
              } else {
                  error.appendTo(element.parent());
              }
          },
          errorClass: "help-block m-b-none",
          validClass: "help-block m-b-none"
      });

	function mylaydate(inputId) {

	  	laydate({
			elem : "#" + inputId,
			event : "focus",
		});
	 }

   	//图片上传-需要配合隐藏域使用
	//0-不限制文件类型；1-图片；2-文件文档
	function uploadImage(filed,type,formId) {
		var imageId = $(filed).attr("id");
		$("#" + formId).ajaxSubmit({
			url : "${path }/index/upload",
			type : "post",
			dataType : "json",
			data:{imageId : imageId,type:type,time:Math.random() },
			timeout : 60000,
			success : function(data, textStatus) {
				if(data.code == 1) {
					$("#" + imageId.substr(0,imageId.length - 1)).val(data.path);
				} else {
					swal(data.message);
				}
			},error : function(data, textStatus) {
				swal(data.message);
			}
		});
	}

   	//图片上传-需要配合隐藏域使用，有回调函数
	//0-不限制文件类型；1-图片；2-文件文档
	function uploadImageCallbak(filed,type,formId,callbak) {

		var imageId = $(filed).attr("id");

		$("#" + formId).ajaxSubmit({
			url : "${path }/index/upload",
			type : "post",
			dataType : "json",
			data:{imageId : imageId,type:type,time:Math.random() },
			timeout : 60000,
			success : function(data, textStatus) {
				if(data.code == 1) {
					$("#" + imageId.substr(0,imageId.length - 1)).val(data.path);
					if(callbak) {
						callbak(data);
					}
				} else {
					swal(data.message);
				}
			},error : function(data, textStatus) {
				swal(data.message);
			}
		});
	}


   	//图片上传-需要配合隐藏域使用，有回调函数,返回值不带文件访问的基本路径，后续访问该部分上传的图片需要把基本请求路径加上，如
   	////222.85.156.194:8888/download
	//0-不限制文件类型；1-图片；2-文件文档
	function uploadImageBasePathCallbak(filed,type,formId,callbak) {

		var imageId = $(filed).attr("id");

		$("#" + formId).ajaxSubmit({
			url : "${path }/index/uploadBasePath",
			type : "post",
			dataType : "json",
			data:{imageId : imageId,type:type,time:Math.random() },
			timeout : 60000,
			success : function(data, textStatus) {
				if(data.code == 1) {
					$("#" + imageId.substr(0,imageId.length - 1)).val(data.path);
					if(callbak) {
						callbak(data);
					}
				} else {
					swal(data.message);
				}
			},error : function(data, textStatus) {
				swal(data.message);
			}
		});
	}


	function faceget() {

		$("#myform").ajaxSubmit({
			url : "${path}/enterprise/getFaceRecognition",
			type:"post",
			dataType : "json",
			success : function(json) {

				if(json != null && json != "") {
					$("#faceRecognition").val(json);
				} else {
				 	layer.msg('请上传人员正脸照片!', {
                        icon: 5
                    });

				 	$("#faceRecognition").val("");
				}
			}
		});
	 }

    function getDays(startDate, endDate) {

 		var date1Str = startDate.split("-");//将日期字符串分隔为数组，数组元素分别为年、月、日
		//根据年、月、日的值创建Date对象
       	var date1Obj = new Date(date1Str[0], (date1Str[1] - 1), date1Str[2]);
       	var date2Str = endDate.split("-");
    	var date2Obj = new Date(date2Str[0], (date2Str[1] - 1), date2Str[2]);
       	var t1 = date1Obj.getTime();//返回从1970-1-1开始计算到Date对象中的时间之间的毫秒数
       	var t2 = date2Obj.getTime();//返回从1970-1-1开始计算到Date对象中的时间之间的毫秒数
       	var datetime = 1000 * 60 * 60 * 24; //一天时间的毫秒值
     	var minusDays = Math.floor(((t2 - t1) / datetime));//计算出两个日期天数差
       	var days = minusDays;//如果结果为负数，取绝对值
       	return days;
    }

	//选择派出所
	function selectPolice(id,policeStationId) {
		inputId = id;
		vid = policeStationId;
		layer.open({
			type : 2,
			content : '${path}/police/selectpolice', //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['//sentsin.com', 'no']
			area : [ '900px', '500px' ],
			title : [ '选择辖区派出所', 'font-size:18px;' ]
		});
	}

	function getPolice(id,name) {
		$("#"+inputId).val(name);//jquery通过name属性获取html对象并赋值
		$("#"+vid).val(id);//jquery通过name属性获取html对象并赋值
		layer.closeAll();
	}

	function fileshow(id) {
		layer.open({
			type: 1,
			content: "<a href='${path }/common/persionImg?filepath="+id+"'>564456456456456</a>", //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['//sentsin.com', 'no']
			area: ['100%', '100%'],
			// title: ['文件上传页面', 'font-size:18px;']
		});
	}

	function downloads(inputId) {
		var aid = $("#"+inputId).val()
		if(inputId.length == 0){
           layer.msg('上传文件为空', {icon: 5});
			return;
		}
		location.href="${path}/enterprise/download?status=0&attachId="+inputId;
	}

    function apiDownloads(inputId) {
       var aid = $("#"+inputId).val()
       if(inputId.length == 0){
          layer.msg('上传文件为空', {icon: 5});
          return;
       }
       location.href="${path}/api/v1/projectRecord/download?status=0&attachId="+inputId;
    }

	// 合同下载
	function downloadContract(inputId) {
		if(inputId.length == 0){
           layer.msg('上传文件为空', {icon: 5});
			return;
		}
		location.href="${pageContext.request.contextPath}/api/v1/projectRecord/download/"+inputId+"?state=1";
	}

    //js动态选中
    function selectOption(id,val) {
       var titleTypes = document.getElementById(id);
       for(var i=0; i<titleTypes.options.length; i++){
          if(titleTypes.options[i].value == val){
             titleTypes.options[i].selected = true;
             break;
          }
       }
    }
    /**
     *
     *传入城市/区域名称查询邮政编码
     * */
    function getZipCode(inputId,areaName) {
       $.ajax({
          url:"//ali-city.showapi.com/areaName?level=3&maxSize=20&page=1&areaName="+areaName,
          type:"GET",
          headers:{
             Authorization:'APPCODE cffe7eb1b7e64714902c0727da7102f6'},//阿里云身份验证
          dataType:"json",
          success:function(json){
                if(json.showapi_res_body.data.length!= 0){
                   /**
                    *   返回值参数说明
                    *"provinceId": "",//省份id
                    "simpleName": "上海",//简称
                    "lon": "121.472644",
                    "areaCode": "",//区域码
                    "cityId": "0", //市id
                    "remark": "", //备注
                    "id": "310000000000",//id
                    "pinYin": "Shanghai", //拼音
                    "parentId": "0",//父id
                    "level": 1,//级别 1省 2市 3县 4乡镇
                    "areaName": "上海",//区域名称;
                    "simplePy": "SH",//缩写
                    "zipCode": "",//邮政编码
                    "countyId": "0",//县 id
                    "lat": "31.231706",//经纬度
                    "wholeName": "中国,上海" // 完整名称
                    */
                   $("#"+inputId).val(json.showapi_res_body.data[0].zipCode);
                   layer.msg("已查询到该区域邮政编码!")
                }else {
                   layer.msg("没有查询到该区域邮政编码!",{icon:5});

                }
          },
          error:function(jqXHR){
             console.log("Error: "+jqXHR.status);
          }
       });
    }


    function return_btn() {
       parent.layer.closeAll();
    }

</script>
